<template>
    <div>
      <van-form @submit="onSubmit" ref="addForm">
        <van-field
          v-model="goodsName"
          name="goodsName"
          placeholder="请输入商品名称"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </div>
</template>

<script>
export default {
  data() {
    return {
      goodsName:''
    }
  },

  created() {

  },
  
  methods: {
    // 提交事件
     async onSubmit(obj) {
      if(obj.goodsName.trim()=="")
      {
        this.goodsName=""
        this.$notify('请输入商品名称')
       
      }else
      {
        const {data:res}=await this.$axios.post('/api/addproduct',{name:this.goodsName})
        if(res.message!="添加成功") return this.$notify('添加失败')
        this.$notify({type:"success",message:"添加成功"})
        this.$router.push('/search')
      }
      
    }
  }
};
</script>

<style scoped lang='less'>

</style>
